package com.yuexun.beilunpatient.ui.visit.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuexun.beilunpatient.R;
import com.yuexun.beilunpatient.base.BaseKJActivity;
import com.yuexun.beilunpatient.baselistener.ICallBackListener;
import com.yuexun.beilunpatient.ui.visit.ui.fragment.Frag_Visit_Draftbox;
import com.yuexun.beilunpatient.ui.visit.ui.fragment.Frag_Visit_Movevisit;
import com.yuexun.beilunpatient.widget.timeUtil.CustomDatePicker;

import org.kymjs.kjframe.ui.KJFragment;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2018/4/13 0013.
 */

public class Act_Visit_Main extends BaseKJActivity {

    @Bind(R.id.movevisit)
    TextView movevisit;
    @Bind(R.id.movevisit_img)
    ImageView movevisitImg;
    @Bind(R.id.draftbox)
    TextView draftbox;
    @Bind(R.id.draftbox_img)
    ImageView draftboxImg;
    @Bind(R.id.start_date)
    TextView startDate;
    @Bind(R.id.end_date)
    TextView endDate;
    @Bind(R.id.et_search)
    EditText etSearch;

    KJFragment fragDraftbox;
    KJFragment fragMovevisit;
    ICallBackListener backListener;

    public void setOnCallBack(ICallBackListener backListener) {
        this.backListener = backListener;
    }

    @Override
    public void setRootView() {
        setContentView(R.layout.act_visit_main);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        startDate.setText(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        endDate.setText(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        fragMovevisit = new Frag_Visit_Movevisit();
        fragDraftbox = new Frag_Visit_Draftbox();
        setOnCallBack((ICallBackListener) fragMovevisit);
        changeFragment(R.id.frag_content, fragMovevisit);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.title_back, R.id.movevisit_ll, R.id.draftbox_ll, R.id.start_date, R.id.end_date, R.id.tv_search, R.id.add_visit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_back:
                finish();
                break;
            case R.id.movevisit_ll:
                movevisit.setTextColor(getResources().getColor(R.color.main_text_02));
                movevisitImg.setBackgroundColor(getResources().getColor(R.color.main_text_02));
                draftbox.setTextColor(getResources().getColor(R.color.txt_black1));
                draftboxImg.setBackgroundColor(getResources().getColor(R.color.transparent));
                setOnCallBack((ICallBackListener) fragMovevisit);
                changeFragment(R.id.frag_content, fragMovevisit);
                break;
            case R.id.draftbox_ll:
                movevisit.setTextColor(getResources().getColor(R.color.txt_black1));
                movevisitImg.setBackgroundColor(getResources().getColor(R.color.transparent));
                draftbox.setTextColor(getResources().getColor(R.color.main_text_02));
                draftboxImg.setBackgroundColor(getResources().getColor(R.color.main_text_02));
                setOnCallBack((ICallBackListener) fragDraftbox);
                changeFragment(R.id.frag_content, fragDraftbox);
                break;
            case R.id.start_date:
                CustomDatePicker customDatePicker = new CustomDatePicker(this, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        startDate.setText(time);
                    }
                }, "2010-01-01 00:00", startDate.getText().toString() + " 00:00"); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 显示时和分
                customDatePicker.setIsLoop(true); // 不允许循环滚动
                customDatePicker.setIsLessNow(1, endDate.getText().toString());
                customDatePicker.show(startDate.getText().toString() + " 00:00");
                break;
            case R.id.end_date:
                CustomDatePicker customDatePicker1 = new CustomDatePicker(this, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        endDate.setText(time);
                    }
                }, "2010-01-01 00:00", endDate.getText().toString() + " 00:00"); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker1.showSpecificTime(false); // 显示时和分
                customDatePicker1.setIsLoop(true); // 不允许循环滚动
                customDatePicker1.setIsLessNow(2, startDate.getText().toString());
                customDatePicker1.show(endDate.getText().toString() + " 00:00");
                break;
            case R.id.tv_search:
                break;
            case R.id.add_visit:
                startActivity(new Intent(aty, Act_Visit_Add.class));
                break;
        }
    }
}
